--------------------------------------------------
-- Level code
-- Created 18:33 2021-2-5
--------------------------------------------------
local redCoins = require("Libraries/redCoins")
redCoins.ID = 258
redCoins.x = 642
redCoins.y = 66
redCoins.SeqSFX = "redCoins/sm64_red_coin_"
redCoins.SeqFormat = ".wav"

-- Run code on level start
function onStart()
    --Your code here
end

-- Run code every frame (~1/65 second)
-- (code will be executed before game logic will be processed)
function onTick()
	for key, value in ipairs(NPC.get(196, -1)) do
		if not value.StoredY then
			value.StoredY = value.y
		end
		value.y = value.StoredY
	end
	if Level.winState() == 6 then
		Level.winState(1)
		-- SFX.play(19)
	end
end

-- Run code when internal event of the SMBX Engine has been triggered
-- eventName - name of triggered event
function onEvent(eventName)
    --Your code here
end

function onEventDirect(eventToken, eventName)
	if globalsave.HardMode then
		if eventName == "Rising Lava" or eventName == "Speed Up" or eventName == "EXTREME SPEED" then
			eventToken.cancelled = true
			triggerEvent(eventName .. " HARD")
		end
	end
end